package com.yedean.mall.portal.controller;

import com.alibaba.fastjson.JSONObject;
import com.yedean.mall.common.api.CommonResult;
import com.yedean.mall.model.PmsProductCategory;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;

/**
 * 首页内容管理Controller
 * Created by yedean on 2022/3/21.
 */
@Controller
@RequestMapping("/client")
public class ClientController {
    @Autowired
    RestTemplate restTemplate;

    @ApiOperation("首页内容信息展示")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsProductCategory>> connect() {

        HttpHeaders headers = new HttpHeaders();
        HttpEntity<Object> httpEntity = new HttpEntity<>(headers);
        String url = "http://127.0.0.1:8085/home/productCateList/{parentId}";
        HashMap<String, String> uriVariables = new HashMap<>();
        uriVariables.put("parentId", "1");
        ResponseEntity<String> result = restTemplate.getForEntity(url, String.class, uriVariables);
        Object parse = JSONObject.parse(result.getBody());

        return null;
    }
}
